/**
 * 大厅二级按钮组件
 */
var HallLv2Unit = Unit.extend({
    //按钮列表: 0：图片；1：按钮名字；
    _btnsList: [
        ['_clickSub_Zjh', 'btn_pinsanzhang'],
        ['_clickSub_Nn', 'btn_niuniu'],
        ['_clickSub_Pdk', 'btn_paodekuai'],
        ['_clickSub_Mj', 'btn_majiang'],
        ['_clickSub_Changpai', 'btn_changpai'],
        ['_clickSub_Erpizi', 'btn_erpizi'],
        ['_clickSub_Hz', 'btn_zipai'],
        ['_clickSub_Landlord', 'btn_doudizhu'],
        ['_clickSub_Sdr', 'btn_shangdaren'],
        ['_clickSub_Tuolaji', 'btn_tuolaij'],
        ['_clickSub_Fsp', 'btn_fansanpi'],
        ['_clickSub_LongCheng', 'btn_longcheng'],
        ['_clickSub_JiangShan', 'btn_jiangshan'],
        ['_clickSub_doushisi', 'btn_doushisi'],
        ['_clickSub_ddz', 'btn_ddz'],

        ['_clickMoreJB', 'btn_more_jb'],
        ['_clickSub_jbc_ddz', 'btn_jbc_ddz'],
        ['_clickSub_jbc_pdk', 'btn_jbc_pdk'],
        ['_clickSub_jbc_xl', 'btn_jbc_xl'],
        ['_clickSub_bs_ddz', 'btn_bs_ddz'],

        ['_clickSub_web_meiren', 'btn_web_meiren'],
        ['_clickSub_web_longcheng', 'btn_web_longcheng'],
        ['_clickSub_web_shiguang', 'btn_web_shiguang'],
        ['_clickSub_web_rxby', 'btn_web_rxby'],
    ],
    _btnsListMore: [
        // ['/res/mainmodules/xiangxi/ccs/hall/image/btn_lv2_majiang.png', '_clickWsk', '五十K'],
    ],

    _ccsFileName: res.HallLv2Unit_json,
    /**
     * 初始化
     */
    initUnit:function(){
        this._inReview();
        this._btnMore = this._nodeList['btn_more'];
        /**
         * 网页游戏
         */
        this._nodeList['btn_web_meiren'].setVisible(window['webGame'] && webGame.isOpenWebGame);
        this._nodeList['btn_web_longcheng'].setVisible(window['webGame'] && webGame.isOpenWebGame);
        this._nodeList['btn_web_shiguang'].setVisible(window['webGame'] && webGame.isOpenWebGame);
        //this._nodeList['btn_web_rxby'].setVisible(false);
        if(window['webGame'] && webGame.res.sp_chuanqi_json){
            var sp_chuanqi = playSpine(webGame.res.sp_chuanqi_json, 'animation', true);
            sp_chuanqi.setPosition(cc.p(123/2,123/2));
            sp_chuanqi.setScale(1.08);
            this._nodeList['btn_web_longcheng'].addChild(sp_chuanqi);
        }
        if(window['webGame'] && webGame.res.sp_jiangshan2_json){
            var sp_jiangshan2 = playSpine(webGame.res.sp_jiangshan2_json, 'animation', true);
            sp_jiangshan2.setPosition(cc.p(123/2,123/2));
            this._nodeList['btn_web_meiren'].addChild(sp_jiangshan2);
        }
        if(window['webGame'] && webGame.res.sp_rexuechuanqi_json){
            var sp_jiangshan2 = playSpine(webGame.res.sp_rexuechuanqi_json, 'animation', true);
            sp_jiangshan2.setPosition(cc.p(123/2,123/2));
            this._nodeList['btn_web_rxby'].addChild(sp_jiangshan2);
        }
    },
    /**
     * 初始化提审隐藏
     * @protected
     */
    _inReview: function () {
        if (!window.inReview) {
            return;
        }
    },
    _initClickListeners: function () {
        Unit.prototype._initClickListeners.call(this);
        this._clickListeners = {
            'btn_more': '_clickMore',
        };
        for (var i = 0; i < this._btnsList.length; i++) {
            var _name = this._btnsList[i][1];
            var btn = this._nodeList[_name];
            if (btn) {
                btn.setTag(i);
                this._clickListeners[_name] = '_clickButton';
            }
        }
    },
    /**
     * 设置更多按钮里面的小游戏图标
     * @private
     */
    _initMoreButton: function () {
        var _list = this._btnsListMore;
        var _ox = 26;
        var _oy = 96;
        var _w = 36;
        var _h = 36;
        var _sc = 0.26;
        for (var i in _list) {
            var param = _list[i][0];
            if (param && param.length > 0) {
                var sp = new cc.Sprite(param);
                if (!!sp) {
                    sp.setScale(_sc);
                    this._btnMore.addChild(sp);
                    sp.x = (i % 3) * _w + _ox;
                    sp.y = _oy - parseInt(i / 3) * _h;
                }
            }
        }
    },
    /**
     * 点击更多
     * @private
     */
    _clickMore: function () {
    },
    /**
     * 点击按钮
     * @private
     */
    _clickButton: function (btn) {
        var tag = btn.getTag();
        var param = this._btnsList[tag];
        if (!param) return;
        //点击
        var _click = param[0];
        if (_click && _click.length > 0) {
            window.eventManager.dispatchEvent(EventKey.HallBoardRoomBtnEvent, {click:_click});
        }
    }
});